IF exists(SELECT * FROM dbo.sysobjects WHERE name='TeXvertaal' AND xtype='FN') 
BEGIN
	DROP FUNCTION TeXvertaal
END
GO

CREATE   function TeXvertaal
(@bron varchar(8000))
 returns varchar(8000)
as
begin
  declare @i int
  declare @c varchar(1)
  declare @ic int
  declare @doel varchar(8000)
  set @i = 1
  set @doel = ''

  while (@i <= len(@bron) )
   begin
     set @c = (substring(@bron,@i,1))
     set @ic = ascii(@c)
     set @doel = @doel + 
	case when @ic = 35  then '\#'	
	when @ic = 36 then '\$'
	when @ic = 37 then '\%'
	when @ic = 38 then '\&'
	when @ic = 92 then '\backslash'
	when @ic = 94 then '\^{}'
	when @ic = 95 then '\_'
	when @ic = 128 then 'euro'
	when @ic between 125 and 159  then ''
	when @ic = 162 then ''
	when @ic between 164 and 166 then ''
	when @ic = 177 then '$\pm$'
	when @ic = 181 then ''
	when @ic = 185 then ''
	when @ic = 208 then ''
	when @ic = 215 then ''
	when @ic = 222 then ''
	when @ic = 240 then ''
	when @ic = 247 then ''
	when @ic = 254 then ''
     	else @c 
	end
     set @i=@i+1
   end
  return(@doel)
end